<%@ page import="com.oval.util.JspHelper" %>
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="com.oval.foundation.util.*" %>
<%@ page import="com.oval.foundation.engine.*" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%--Search for an item--%>

<%
 
  OvalSearchAPI osa = new OvalSearchAPI();
  Vector columns = new Vector();
  String module = OvalEncode.convertEncode(request.getParameter("module"),"iso-8859-1","utf-8");
  String columnname = OvalEncode.convertEncode(request.getParameter("columnname"),"iso-8859-1","utf-8");
  String columndesc = OvalEncode.convertEncode(request.getParameter("columndesc"),"iso-8859-1","utf-8");
  String languagecode = OvalEncode.convertEncode(request.getParameter("languagecode"),"iso-8859-1","utf-8");
  String tablename = OvalEncode.convertEncode(request.getParameter("tablename"),"iso-8859-1","utf-8");
  String whereclause = "";
  if(module != null && module.length() != 0)
    whereclause += " and module like '" + module + "'";
  if(columnname != null && columnname.length() != 0)
    whereclause += " and columnname like '" + columnname + "'";
  if(columndesc != null && columndesc.length() != 0)
    whereclause += " and columndesc like '" + columndesc + "'";
  if(languagecode != null && languagecode.length() != 0)
    whereclause += " and languagecode='" + languagecode + "'";
  if(tablename != null && tablename.length() != 0)
    whereclause += " and tablename like '" + tablename + "'";
  whereclause += " order by module asc, columnname asc"; 
    
  if(module != null)
    columns = osa.getSearchResults("ovovalcolumn",whereclause,null,null);
%>
<html>
<head>
<title>e-manager</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/chinese/csscontent.css" type="text/css"> 
<script language="JavaScript" src="../css/chinese/script.js"></script>

<%--Check what to do if press the corresponding button--%>

<script language="JavaScript">
function page_search()
{
  frm.actionname.value = "search"; 
  if(!isEmpty(frm.languagecode.value) && frm.languagecode.value != "cn" && frm.languagecode.value != "en" && frm.languagecode.value != "jp")
  {
    alert("Language Code must be cn/en/jp!");
    return;
  }
  document.frm.submit();
}
function page_add()
{
  self.location.href = "columnAdd.jsp?module=" + frm.module.value;
}
function page_edit()
{
  var checkTimes = 0;
  for(var i=0;i<frm.checkedIds.length;i++)  
  {
    if(frm.checkedIds[i].checked == 1)
    {
      checkTimes = checkTimes + 1;
    }
  }
  if(checkTimes > 3)
  {
    alert("Please only check three box!");
    return;  
  }
  frm.actionname.value = "edit";
  if(isNullChecked(document.frm.checkedIds))
  {
    alert("Choose the edit column,Please!");
    return;
  }
  document.frm.action = "columnEdit.jsp";
  document.frm.submit();
}
function page_delete()
{
  frm.actionname.value = "delete";
  if(isNullChecked(document.frm.checkedIds))
  {
    alert("Choose the delete column,Please!");
    return;
  }
  document.frm.action = "columnAction.jsp";
  document.frm.submit();
}

function clickid(index)
{
   if(frm.checkedIds[0] == null)
   {
   	return;
   }
  var lc = frm.checkedIds[index].columnselect;
  frm.edit_module.value = frm.checkedIds[index].module;
  frm.edit_columnname.value = frm.checkedIds[index].columnname;
  frm.edit_tablename.value = frm.checkedIds[index].tablename;
  if(frm.checkedIds[index].languagecode == "en")
  {
    frm.edit_columndescen.value = frm.checkedIds[index].columndesc;
    frm.edit_enid.value = frm.checkedIds[index].columnid;
  }
  else if(frm.checkedIds[index].languagecode == "cn")
  {
    frm.edit_columndesccn.value = frm.checkedIds[index].columndesc;
    frm.edit_cnid.value = frm.checkedIds[index].columnid;
  }
  else
  {
    frm.edit_columndescjp.value = frm.checkedIds[index].columndesc;
    frm.edit_jpid.value = frm.checkedIds[index].columnid;
  }
  var flag = frm.checkedIds[index].checked;
  for(var i=0;i<frm.checkedIds.length;i++)  
  {
    if(frm.checkedIds[i].columnselect == lc)
    {  
      frm.checkedIds[i].checked = flag;
      if(frm.checkedIds[i].languagecode == "en")
      {	
	frm.edit_columndescen.value = frm.checkedIds[i].columndesc;
	frm.edit_enid.value = frm.checkedIds[i].columnid;
      }
      else if(frm.checkedIds[i].languagecode == "cn")
      {
	frm.edit_columndesccn.value = frm.checkedIds[i].columndesc;
	frm.edit_cnid.value = frm.checkedIds[i].columnid;
      }
      else
      {
	frm.edit_columndescjp.value = frm.checkedIds[i].columndesc;
	frm.edit_jpid.value = frm.checkedIds[i].columnid;
      }
    }
  }
}

<%--Display First Line--%>  

</script>
</head>
<body>
<form name="frm" action="columnSummary.jsp">
  <input type="hidden" name="actionname">
  <input type="hidden" name="edit_columnname">
  <input type="hidden" name="edit_columndesccn">
  <input type="hidden" name="edit_columndescen">
  <input type="hidden" name="edit_columndescjp">
  <input type="hidden" name="edit_module">
  <input type="hidden" name="edit_tablename">
  <input type="hidden" name="edit_cnid">
  <input type="hidden" name="edit_enid">
  <input type="hidden" name="edit_jpid">
<table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#999999">
 <tr align="center">
  <td>MODULE:</td><td class="input"><input type="text" name="module" size="5" value="<%=JspHelper.filterNull( request.getParameter("module") )%>" onkeydown="javascript:if(window.event.keyCode == 13)page_search();"></td> 
  <td>columnName:</td><td class="input"><input type="text" name="columnname" size="10" value="<%=JspHelper.filterNull( request.getParameter("columnname") )%>" onkeydown="javascript:if(window.event.keyCode == 13)page_search();"></td> 
  <td>LanguageCode:</td><td class="input"><input type="text" name="languagecode" size="3" value="<%=JspHelper.filterNull( request.getParameter("languagecode") )%>" onkeydown="javascript:if(window.event.keyCode == 13)page_search();"></td> 
  <td>columnDesc:</td><td class="input"><input type="text" name="columndesc" size="10" value="<%=JspHelper.filterNull( request.getParameter("columndesc") )%>" onkeydown="javascript:if(window.event.keyCode == 13)page_search();"></td> 
  <td>tableName:</td><td class="input"><input type="text" name="tablename" size="10" value="<%=JspHelper.filterNull( request.getParameter("tablename") )%>" onkeydown="javascript:if(window.event.keyCode == 13)page_search();"></td> 
 </tr>
 <tr align="center">
  <td><input type="button" name="Search" value="Search" onclick="javascript:page_search()"></td>
  <td><input type="button" name="Add" value="Add" onclick="javascript:page_add()"></td>
  <td><input type="button" name="Edit" value="Edit" onclick="javascript:page_edit()"></td>
  <td><input type="button" name="Delete" value="Delete" onclick="javascript:page_delete()"></td>
 </tr>
</table>

<%--Display Second Line--%>

<table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#999999">
  <tr> 
    <td class="td_title_bg">
      &nbsp;
    </td>
    <td class="td_title_bg">
      Module Name
    </td>
    <td class="td_title_bg">
      Column Name
    </td>
     <td class="td_title_bg">
      Language Code
    </td>
    <td class="td_title_bg">
      Column Desc
    </td>
    <td class="td_title_bg">
      Table Name
    </td>
  </tr>

<%--Display the items--%>

  <% 
     for(int i=0;i<columns.size();i++)
     {
       HashMap temp = (HashMap)columns.get(i);
  %>
     <tr class="td_bg_row"> 
       <td>
         <div align="center">
          <input type="checkbox" border=0 style="border:0" name="checkedIds" columnselect="<%=JspHelper.filterNull( temp.get("tablename")+"_"+temp.get("columnname") )%>" columnname="<%=JspHelper.filterNull( temp.get("columnname") )%>" module="<%=JspHelper.filterNull( temp.get("module") )%>" languagecode="<%=JspHelper.filterNull( temp.get("languagecode") )%>" columnid="<%=JspHelper.filterNull( temp.get("columnid") )%>" columndesc="<%=JspHelper.filterNull( temp.get("columndesc") )%>" tablename="<%=JspHelper.filterNull( temp.get("tablename") )%>" value="<%=JspHelper.filterNull( temp.get("columnid") )%>" onclick="javascript:clickid(<%=JspHelper.filterNull( i )%>)">
         </div>
       </td>
       <td class="td_center">
         <div align="left">
           <%=JspHelper.filterNull( temp.get("module") )%>&nbsp;
         </div>
       </td>
       <td class="td_center">
         <div align="left">
           <%=JspHelper.filterNull( temp.get("columnname") )%>&nbsp;
         </div>
       </td>
       <td class="td_center">
         <div align="left">
           <%=JspHelper.filterNull( temp.get("languagecode") )%>&nbsp;
         </div>
       </td>
       <td class="td_center">
         <div align="left">
           <%=JspHelper.filterNull( temp.get("columndesc") )%>&nbsp;
         </div>
       </td>
       <td class="td_center">
         <div align="left">
           <%=JspHelper.filterNull( temp.get("tablename") )%>&nbsp;
         </div>
       </td>
     </tr>
  <% } %>
</table>
</form>
</body>
</html>

